package net.zjitc.service.Impl;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.util.List;
import net.zjitc.dao.ProductDao;
import net.zjitc.pojo.Evaluate;
import net.zjitc.pojo.Product;
import net.zjitc.redis.Redis;
import net.zjitc.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/4/26 15:44
 * @description:
 */
@Service
public class ProductServiceImpl implements ProductService {
  @Autowired
  private ProductDao productdao;
  @Autowired
  private Jedis jedis;
  @Autowired
  private Redis redis;
  @Override
  public List<Product> findAllProduct() {
    return productdao.findAllProduct();
  }

  @Override
  public List<Product> findHot() {
    return productdao.findHot();
  }

  @Override
  public List<Product> findNew() {
    return productdao.findNew();
  }

  @Override
  public List<Product> findPageByCid(Integer cid) {
    return productdao.findPageByCid(cid);
  }

  @Override
  public List<Product> findPageByCsid(Integer csid) {
    return productdao.findPageByCsid(csid);
  }

  @Override
  public Product findByPid(Integer pid) {
    return productdao.findByPid(pid);
  }

  @Override
  public List<Evaluate> findEvaluate(Integer pid) {
    return productdao.findEvaluate(pid);
  }
  @Override
  public Integer editProduct(Product product) {
    System.out.println(product);
    Integer integer=productdao.editProduct(product);
    Gson gson =new Gson();
    List<Product> productList =productdao.adminProduct();
    String ProductList = gson.toJson(productList);
    redis.set("product", ProductList);
    return null;
  }

  @Override
  public Integer addEvaluate(Evaluate evaluate) {
    return productdao.addEvaluate(evaluate);
  }

  @Override
  public Integer deleteProduct(Integer pid) {
    Integer integer= productdao.deleteProduct(pid);
    Gson gson =new Gson();
    List<Product> productList = productdao.adminProduct();
    String ProductList = gson.toJson(productList);
    redis.set("product", ProductList);
    return null;
  }

  @Override
  public void addProduct(Product product) {
    productdao.addProduct(product);
    Gson gson =new Gson();
    List<Product> productList = productdao.adminProduct();
    String ProductList = gson.toJson(productList);
    redis.set("product", ProductList);
    return;
  }

  @Override
  public void updateProduct(Product product) {
    productdao.updateProduct(product);
    Gson gson =new Gson();
    List<Product> productList = productdao.adminProduct();
    String ProductList = gson.toJson(productList);
    redis.set("product", ProductList);
    return;
  }
}
